package leetcode.offer;

import leetcode.base.TreeNode;

/**
 * ClassName: Offer54_KthLargest
 * Description: LeetCode - 剑指offer 54 二叉搜索树的第k大的节点
 * date: 2021-11-10 18:15
 *
 * @author liyifan
 */
public class Offer54_KthLargest {

    int res;

    int k;

    public int kthLargest(TreeNode root, int k) {
        this.k = k;
        dfs(root);
        return res;
    }

    public void dfs(TreeNode root) {
        if (root == null)
            return;
        dfs(root.right);
        if (--k == 0) {
            res = root.val;
            return;
        }
        dfs(root.left);

    }
}
